import bpy

from 节点.全局控制.Node.节点和插座基类 import bl_节点基类

import Core.bl_UI配色 as UI配色

import engine.initLIB.load_dll as engineLib
import ctypes




engineLib.flexCAPI.f_创建I32_Array2D_展平节点.restype = ctypes.c_bool
engineLib.flexCAPI.f_创建容器数据偏移节点.restype = ctypes.c_bool

engineLib.flexCAPI.f_创建改组节点.restype = ctypes.c_bool






class C_Node_F32_Array1D_合并(bl_节点基类.C_Node_基类):
	bl_dname = 'bl_node_F32_Array1D_合并'
	bl_label = 'F32_Array1D_合并'

	m_拷贝到内部 = bpy.props.BoolProperty(default=True)
	def init(self, context):
		super(C_Node_F32_Array1D_排序, self).f_init(context)
		self.inputs.new('C_Socket_I32', name='序列偏移')

		self.outputs.new('C_Socket_图像', name='bl图像')
		self.f_toCPP()

		self.use_custom_color = True
		self.color = UI配色.g_内部节点颜色


	def f_toCPP(self):
		engineLib.flexCAPI.f_创建图像节点(ctypes.c_wchar_p(self.id_data.name), ctypes.c_wchar_p(self.name), self.f_getPyObject());
		
	def draw_buttons(self, context, layout):
		layout.prop(self, "m_拷贝到内部", text="拷贝到内部")
		engineLib.flexCAPI.f_node_传入BL数据(ctypes.c_wchar_p(self.id_data.name), ctypes.c_wchar_p(self.name), ctypes.py_object(data));

		
class C_NODE_MENU_F32_Array1D_合并(bpy.types.Operator):
	bl_idname = 'node.create_node_texture'
	bl_label = 'F32_Array1D_合并'
	bl_options = {'REGISTER', 'UNDO'}
	def execute(self, context):
		bpy.ops.node.add_node(type='C_Node_F32_Array1D_合并', use_transform=True)
		return {'FINISHED'}
		















class C_Node_vec3_Array1D_合并(bl_节点基类.C_Node_基类):
	bl_dname = 'bl_node_vec3_Array1D_合并'
	bl_label = 'vec3_Array1D_合并'

	m_拷贝到内部 = bpy.props.BoolProperty(default=True)
	def init(self, context):
		super(C_Node_F32_Array1D_排序, self).f_init(context)
		self.inputs.new('C_Socket_I32', name='序列偏移')

		self.outputs.new('C_Socket_图像', name='bl图像')
		self.f_toCPP()

		self.use_custom_color = True
		self.color = UI配色.g_内部节点颜色


	def f_toCPP(self):
		engineLib.flexCAPI.f_创建图像节点(ctypes.c_wchar_p(self.id_data.name), ctypes.c_wchar_p(self.name), self.f_getPyObject());
		
	def draw_buttons(self, context, layout):
		layout.prop(self, "m_拷贝到内部", text="拷贝到内部")
		engineLib.flexCAPI.f_node_传入BL数据(ctypes.c_wchar_p(self.id_data.name), ctypes.c_wchar_p(self.name), ctypes.py_object(data));

	
		
class C_NODE_MENU_vec3_Array1D_合并(bpy.types.Operator):
	bl_idname = 'node.create_node_texture'
	bl_label = 'vec3_Array1D_合并'
	bl_options = {'REGISTER', 'UNDO'}
	def execute(self, context):
		bpy.ops.node.add_node(type='C_Node_vec3_Array1D_合并', use_transform=True)
		return {'FINISHED'}























class C_Node_I32_Array2D_展平(bl_节点基类.C_Node_基类):
	bl_dname = 'bl_node_I32_Array2D_展平'
	bl_label = 'I32_Array2D_展平'
	
	def init(self, context):
		super(C_Node_I32_Array2D_展平, self).f_init(context)
		self.inputs.new('C_Socket_I32_Array2D', name='源')
		self.outputs.new('C_Socket_I32_Array1D', name='var')
		self.f_toCPP()

		self.use_custom_color = True
		self.color = UI配色.g_内部节点颜色

	def f_toCPP(self):
		是否更新 = engineLib.flexCAPI.f_创建I32_Array2D_展平节点(ctypes.c_wchar_p(self.id_data.name), ctypes.c_wchar_p(self.name), self.f_getPyObject());

class C_NODE_MENU_I32_Array2D_展平(bpy.types.Operator):
	bl_idname = 'node.create_node_iaiid_flatten'
	bl_label = 'I32_Array2D_展平'
	bl_options = {'REGISTER', 'UNDO'}
	def execute(self, context):
		bpy.ops.node.add_node(type='C_Node_I32_Array2D_展平', use_transform=True)
		return {'FINISHED'}














class C_Node_容器数据偏移(bl_节点基类.C_Node_基类):
	bl_dname = 'bl_node_I32_Array2D_展平'
	bl_label = '容器数据偏移'
	
	def init(self, context):
		super(C_Node_容器数据偏移, self).f_init(context)
		self.inputs.new('C_Socket_引用', name='源')
		self.inputs.new('C_Socket_引用', name='补码')
		self.inputs.new('C_Socket_I32', name='偏移')
		self.outputs.new('C_Socket_引用', name='var')
		self.f_toCPP(self.id_data)
		
	def f_toCPP(self, tree):
		是否更新 = engineLib.flexCAPI.f_创建容器数据偏移节点(ctypes.c_wchar_p(tree.name), ctypes.c_wchar_p(self.name), self.f_getPyObject(tree));
		if 是否更新 :
			self.use_custom_color = True
			self.color = UI配色.g_内部节点颜色
			self.inputs['偏移'].f_update()

class C_NODE_MENU_容器数据偏移(bpy.types.Operator):
	bl_idname = 'node.create_node_container_data_offset'
	bl_label = '容器数据偏移'
	bl_options = {'REGISTER', 'UNDO'}
	def execute(self, context):
		bpy.ops.node.add_node(type='C_Node_容器数据偏移', use_transform=True)
		return {'FINISHED'}











class C_Node_I32_Array1D_重组为Array2D节点(bl_节点基类.C_Node_基类):
	bl_dname = 'bl_node_I32_Array1D_重组为Array2D'
	bl_label = 'I32_Array1D_重组为Array2D'
	
	def init(self, context):
		super(C_Node_I32_Array1D_重组为Array2D节点, self).f_init(context)
		self.inputs.new('C_Socket_I32_Array1D', name='源')
		self.inputs.new('C_Socket_I32', name='列数')
		self.outputs.new('C_Socket_I32_Array2D', name='var')
		self.f_toCPP()

		self.use_custom_color = True
		self.color = UI配色.g_内部节点颜色

	def f_toCPP(self):
		是否更新 = engineLib.flexCAPI.f_创建I32_Array1D_重组为Array2D节点(ctypes.c_wchar_p(self.id_data.name), ctypes.c_wchar_p(self.name), self.f_getPyObject());
		if 是否更新 :
			self.inputs['列数'].f_update()
			
class C_NODE_MENU_I32_Array1D_重组为Array2D(bpy.types.Operator):
	bl_idname = 'node.create_node_iai_reorganization_iaii'
	bl_label = 'I32_Array1D_重组为Array2D'
	bl_options = {'REGISTER', 'UNDO'}
	def execute(self, context):
		bpy.ops.node.add_node(type='C_Node_I32_Array1D_重组为Array2D节点', use_transform=True)
		return {'FINISHED'}

















class C_Node_改组节点(bl_节点基类.C_Node_基类):
	bl_dname = 'bl_node_改组'
	bl_label = '改组'
	
	def init(self, context):
		super(C_Node_改组节点, self).f_init(context)
		self.inputs.new('C_Socket_引用', name='源')
		self.inputs.new('C_Socket_I32', name='种子')
		self.inputs.new('C_Socket_I32', name='数量')
		
		self.outputs.new('C_NodeSocket_动态插座', name='list')
		self.outputs.new('C_Socket_I32_Array1D', name='索引')
		
		self.f_toCPP(self.id_data)
		self.inputs['种子'].f_setData(-1)
		
	def f_toCPP(self, tree):
		是否更新 = engineLib.flexCAPI.f_创建改组节点(ctypes.c_wchar_p(tree.name), ctypes.c_wchar_p(self.name), self.f_getPyObject(tree));
		if 是否更新 :
			self.use_custom_color = True
			self.color = UI配色.g_容器操作类节点颜色
			
			self.inputs['数量'].f_update()
			self.inputs['种子'].f_update()

			
class C_NODE_MENU_改组节点(bpy.types.Operator):
	bl_idname = 'node.create_node_shuffle'
	bl_label = '改组'
	bl_options = {'REGISTER', 'UNDO'}
	def execute(self, context):
		bpy.ops.node.add_node(type='C_Node_改组节点', use_transform=True)
		return {'FINISHED'}




classes = (
	C_Node_F32_Array1D_合并,
	C_NODE_MENU_F32_Array1D_合并,

	C_Node_vec3_Array1D_合并,
	C_NODE_MENU_vec3_Array1D_合并,
	

	C_Node_I32_Array2D_展平,
	C_NODE_MENU_I32_Array2D_展平,


	C_Node_容器数据偏移,
	C_NODE_MENU_容器数据偏移,


	C_Node_I32_Array1D_重组为Array2D节点,
	C_NODE_MENU_I32_Array1D_重组为Array2D,


	C_Node_改组节点,
	C_NODE_MENU_改组节点,


)

def register():
	for c in classes:
		bpy.utils.register_class(c)
		
def unregister():
	for c in classes:
		bpy.utils.unregister_class(c)






